package com.by.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.by.core.bean.ResultBean;
import com.by.core.controller.BaseController;
import com.by.entity.Spu;
import com.by.service.SpuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "商品")
@RestController
@RequestMapping("/api")
public class SpuController extends BaseController {
    @Autowired
    SpuService spuService;
    @PostMapping("/spu")
    @ApiOperation("保存")
    public ResultBean save(@RequestBody Spu spu){
        boolean save = spuService.save(spu);
        return success("保存成功",save);
    }
    @GetMapping("/spu")
    @ApiOperation("分页查询")
    public ResultBean list(int page,int pageSize){
        IPage<Spu> iPage=new Page<>(page,pageSize);
        List<Spu> list = spuService.list(iPage);
        return success("查询成功",list);
    }

}
